/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduling;

import java.io.File;
import java.util.Date;
import javax.ejb.Schedule;
import javax.ejb.Stateless;

/**
 *
 * @author damfercer
 */
@Stateless
public class RemoveFilesEJB {
    private static String videoTempPath="/Recruitery/videos";
    private static String imageTempPath="/Recruitery/candidateImages";
    /*private static String imageTempPath="/Users/damfercer/candidateImages";
    private static String videoTempPath="/Users/damfercer/videos";*/
    @Schedule(second="0", minute="0", hour="3", dayOfWeek="*", persistent=false)
    public void removeTempFiles() {
        Date now=new Date();
        File videoDirectory=new File(videoTempPath);
        File[] videos=videoDirectory.listFiles();
        for (File video : videos) {
            Long diff=now.getTime()-video.lastModified();
            Long days=diff / 1000 / 60 / 60 / 24;
            if(days>0){
                video.delete();
            }
        }
        
        File imageDirectory=new File(imageTempPath);
        File[] images=imageDirectory.listFiles();
        for (File image : images) {
            Long diff=now.getTime()-image.lastModified();
            Long days=diff / 1000 / 60 / 60 / 24;
            if(days>0){
                image.delete();
            }
        }
    }
}
